package com.example.job_backend.controller;

import com.example.job_backend.model.Position;
import com.example.job_backend.model.Query.PositionQuery;
import com.example.job_backend.model.R;
import com.example.job_backend.service.PositionService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/api")
public class PositionController {
    @Resource
    private PositionService positionService;

    @GetMapping("/getPositionWx")
    public R getPositionWx(){
        List<Position> list=positionService.list();
        return new R(200,"请求成功",list);
    }

    @GetMapping("/getPositionById/{id}")
    public R getPositionById(@PathVariable("id") Integer id){
        Position position=positionService.getById(id);
        return new R(200,"请求成功",position);
    }

    @GetMapping("/getPosition")
    public R getPositionByPage(PositionQuery query) {
        PageInfo<Position> list = positionService.getPositionByPage(query);
        return new R(200, "请求成功", list);
    }

    @GetMapping("/addPosition")
    public R addPosition(Position position) {
        positionService.save(position);
        return new R(200, "添加成功", null);
    }

    @GetMapping("/deletePosition/{id}")
    public R deletePosition(@PathVariable("id") Integer id){
        positionService.removeById(id);
        return new R(200, "删除成功", null);
    }

    @GetMapping("/updatePosition")
    public R updatePosition(Position position){
        positionService.updateById(position);
        return new R(200, "更新成功", null);
    }
}
